

$(function () {
    $(".reset-btn").click(function (event) {
        var self = $(this);
        var dialog = $('#reset-dialog');
        dialog.modal('show');

        var tr = self.parent().parent();
        var phone = tr.attr("data-phone");
        var pay_pwd = tr.attr("data-pay_pwd");
        if (pay_pwd == 'None'){
            pay_pwd = ''
        }

        var phoneInput = $("input[name='reset_phone']");
        var payInput = $("input[name='pay_pwd']");

        var savebtn = dialog.find("#save-reset-btn");


        phoneInput.val(phone);
        payInput.val(pay_pwd);

        savebtn.attr("data-type",'update');
        savebtn.attr("data-id",tr.attr('data-id'));
    })
});




$(function () {
    $('#save-reset-btn').click(function (event) {
        event.preventDefault();
        var self = $(this);
        var dialog = $('#reset-dialog');

        var payInput = $("input[name='pay_pwd']");
        var phoneInput = $("input[name='reset_phone']");
        var pwdInput = $("input[name='pwd']");

        var pay_pwd = payInput.val();
        var phone = phoneInput.val();
        var pwd = pwdInput.val();
        var submitType = self.attr("data-type");
        var user_id = self.attr('data-id');

        zlajax.post({
            'url': '/cms/reset_user_pwd/',
            'data':{
                'pwd':pwd,
                'phone':phone,
                'pay_pwd':pay_pwd,
                'user_id':user_id,
            },
            'success':function (data) {
                dialog.modal('hide');
                if(data['code']==200){
                    window.location.reload()
                }else{
                    zlalert.alertInfo(data['message']);
                }
            },
            'fail':function () {
                zlalert.alertNetworkError();
            }
        })
    })
});



//  封号
$(function () {
    $(".user-blockade").click(function (event) {
        var self = $(this);
        var dialog = $('#blockade-dialog');
        dialog.modal('show');

        var tr = self.parent().parent();
        var savebtn = dialog.find("#save-blockade-btn");

        savebtn.attr("data-type",'update');
        savebtn.attr("data-id",tr.attr('data-id'));
    })
});


$(function () {
    $('#save-blockade-btn').click(function (event) {
        event.preventDefault();
        var self = $(this);
        var dialog = $('#modify-dialog');

        var tokenInput = $("input[name='token']");

        var token = tokenInput.val();
        var submitType = self.attr("data-type");
        var user_id = self.attr('data-id');


        zlajax.post({
            'url': '/cms/user_blockade/',
            'data':{
                'token':token,
                'user_id':user_id,
            },
            'success':function (data) {
                dialog.modal('hide');
                if(data['code']==200){
                    window.location.reload()
                }else{
                    zlalert.alertInfo(data['message']);
                }
            },
            'fail':function () {
                zlalert.alertNetworkError();
            }
        })
    })
});



$(function () {
    $('.unblock').click(function (event) {
        event.preventDefault();
        var self = $(this);
        var tr = self.parent().parent();
        var user_id = tr.attr('data-id');

        zlajax.post({
            'url': '/cms/user_unblock/',
            'data':{
                'user_id':user_id,
            },
            'success':function (data) {
                if(data['code']==200){
                    zlalert.alertSuccessToast('操作成功');
                    window.location.reload()
                }else{
                    zlalert.alertInfo(data['message']);
                }
            },
            'fail':function () {
                zlalert.alertNetworkError();
            }
        })
    })
});



$(function () {
    $(".shipping-btn").click(function (event) {
        var self = $(this);
        var dialog = $('#shipping-dialog');
        dialog.modal('show');

        var tr = self.parent().parent();
        var shipping_address = tr.attr("data-shipping_address");
        var shipping_name = tr.attr("data-shipping_name");
        var shipping_phone = tr.attr("data-shipping_phone");


        if (shipping_address == 'None'){
            shipping_address = '无';
        }
        if (shipping_name=='None'){
            shipping_name = '无';
        }
        if (shipping_phone=='None'){
            shipping_phone = '无';
        }

        var nameInput = $("input[name='shipping_name']");
        var phoneInput = $("input[name='shipping_phone']");

        var addressInput = $("input[name='shipping_address']");
        var savebtn = dialog.find("#save-modify-btn");


        nameInput.val(shipping_name);
        phoneInput.val(shipping_phone);
        // aliInput.val(ali_pay);
        // weInput.val(we_chat);
        // bankInput.val(bank_card);
        addressInput.val(shipping_address);
        imgInput.val(address_img);

        savebtn.attr("data-type",'update');
        savebtn.attr("data-id",tr.attr('data-id'));
    })
});




$(function () {
    $(".income-btn").click(function (event) {
        var self = $(this);
        var dialog = $('#income-dialog');
        dialog.modal('show');

        var tr = self.parent().parent();
        var income = tr.attr("data-income");
        var income_f = tr.attr("data-income_f");

        var incomeInput = $("input[name='income']");
        var incomedInput = $("input[name='income_f']");

        var savebtn = dialog.find("#save-income-btn");

        incomeInput.val(income);
        incomedInput.val(income_f);

        savebtn.attr("data-type",'update');
        savebtn.attr("data-id",tr.attr('data-id'));
    })
});



$(function () {
    $('#save-income-btn').click(function (event) {
        event.preventDefault();
        var self = $(this);
        var dialog = $('#reset-dialog');

        var income = $("input[name='income']").val();
        var income_f = $("input[name='income_f']").val();

        var submitType = self.attr("data-type");
        var user_id = self.attr('data-id');

        zlajax.post({
            'url': '/cms/update_user_income/',
            'data':{
                'income': income,
                'income_f': income_f,
                'user_id': user_id,
            },
            'success':function (data) {
                dialog.modal('hide');
                if(data['code']==200){
                    window.location.reload()
                }else{
                    zlalert.alertInfo(data['message']);
                }
            },
            'fail':function () {
                zlalert.alertNetworkError();
            }
        })
    })
});


// 账户收款信息
$(function () {
    $(".account-btn").click(function (event) {
        var self = $(this);
        var dialog = $('#account-dialog');
        dialog.modal('show');

        var tr = self.parent().parent();
        var username = tr.attr("data-name");
        var real_name = tr.attr("data-real_name");
        // var ali_pay = tr.attr("data-img");
        var ali_pay_card = tr.attr("data-ali_card");
        var bank_card = tr.attr("data-bank_card");
        var bank_name = tr.attr("data-bank_name");
        // var usdt_address = tr.attr("data-usdt_address");
        // var usdt_img = tr.attr("data-usdt_img");

        var usernameInput = $("input[name='username']");
        var realInput = $("input[name='real_name']");
        // var ali_payInput = $("input[name='ali_pay']");
        var ali_cardInput = $("input[name='ali_pay_card']");
        var bank_cardInput = $("input[name='bank_card']");
        var bank_nameInput = $("input[name='bank_name']");
        // var usdt_addressInput = $("input[name='usdt_address']");
        // var usdt_imgInput = $("input[name='usdt_img']");

        var savebtn = dialog.find("#save-account-btn");

        if (real_name === 'None'){
            real_name = '无';
        }
        if (ali_pay_card === 'None'){
            ali_pay_card = '无';
        }
        if (bank_card === 'None'){
            bank_card = '无';
        }
        if (bank_name === 'None'){
            bank_name = '无';
        }


        usernameInput.val(username);
        realInput.val(real_name);

        ali_cardInput.val(ali_pay_card);

        bank_cardInput.val(bank_card);
        bank_nameInput.val(bank_name);

        savebtn.attr("data-type",'update');
        savebtn.attr("data-id",tr.attr('data-id'));
    })
});



$(function () {
    $('#save-account-btn').click(function (event) {
        event.preventDefault();
        var self = $(this);
        var dialog = $('#reset-dialog');

        var username = $("input[name='username']").val();
        var real_name = $("input[name='real_name']").val();
        var ali_pay_card = $("input[name='ali_pay_card']").val();
        var bank_card = $("input[name='bank_card']").val();
        var bank_name = $("input[name='bank_name']").val();

        var submitType = self.attr("data-type");
        var user_id = self.attr('data-id');


        zlajax.post({
            'url': '/cms/update_user_account/',
            'data':{
                'username': username,
                'real_name': real_name,
                'ali_pay_card': ali_pay_card,
                'bank_card': bank_card,
                'bank_name': bank_name,
                'user_id': user_id,
            },
            'success':function (data) {
                dialog.modal('hide');
                if(data['code']==200){
                    window.location.reload()
                }else{
                    zlalert.alertInfo(data['message']);
                }
            },
            'fail':function () {
                zlalert.alertNetworkError();
            }
        })
    })
});



$(function () {
    $(".user_level").click(function (event) {
        var self = $(this);
        var dialog = $('#level-dialog');
        dialog.modal('show');
        var tr = self.parent().parent();
        var savebtn = dialog.find("#save-level-btn");
        var user_level = tr.attr("data-level");

        var levelInput = $("input[name='user_level']");

        levelInput.val(user_level);

        savebtn.attr("data-type",'update');
        savebtn.attr("data-id",tr.attr('data-id'));
    })
});


$(function () {
    $('#save-level-btn').click(function (event) {
        event.preventDefault();
        var self = $(this);
        var dialog = $('#level-dialog');

        var user_levelInput = $("input[name='user_level']");

        var user_level = user_levelInput.val();
        var submitType = self.attr("data-type");
        var user_id = self.attr('data-id');


        zlajax.post({
            'url': '/cms/set_user_level/',
            'data':{
                'user_level':user_level,
                'user_id':user_id,
            },
            'success':function (data) {
                dialog.modal('hide');
                if(data['code']==200){
                    window.location.reload()
                }else{
                    zlalert.alertInfo(data['message']);
                }
            },
            'fail':function () {
                zlalert.alertNetworkError();
            }
        })
    })
});


// 修改代理等级
$(function () {
    $(".user_level_agent").click(function (event) {
        var self = $(this);
        var dialog = $('#level-agent-dialog');
        dialog.modal('show');
        var tr = self.parent().parent();
        var savebtn = dialog.find("#save-level-agent-btn");
        // var user_level = tr.attr("data-level");
        //
        // var levelInput = $("input[name='user_level']");
        //
        // levelInput.val(user_level);

        savebtn.attr("data-type",'update');
        savebtn.attr("data-id",tr.attr('data-id'));
    })
});


$(function () {
    $('#save-level-agent-btn').click(function (event) {
        event.preventDefault();
        var self = $(this);
        var dialog = $('#level-agent-dialog');

        var user_levelInput = $("input[name='user_level']");

       var user_level_agent = document.getElementsByName("user_level_agent")[0].value;
        var user_id = self.attr('data-id');


        zlajax.post({
            'url': '/cms/set_user_level_agent/',
            'data':{
                'user_level_agent':user_level_agent,
                'user_id':user_id,
            },
            'success':function (data) {
                dialog.modal('hide');
                if(data['code']==200){
                    window.location.reload()
                }else{
                    zlalert.alertInfo(data['message']);
                }
            },
            'fail':function () {
                zlalert.alertNetworkError();
            }
        })
    })
});


// 重置实名
$(function () {
    $('.real-btn').click(function (event) {
        var self = $(this);
        var tr = self.parent().parent();
        var user_id = tr.attr('data-id');
        zlalert.alertConfirm({
            'msg':'您确定要重置实名状态吗？',
            'confirmCallback':function () {
                zlajax.post({
                    'url':'/cms/set_user_real/',
                    'data':{
                        'user_id': user_id
                    },
                    'success':function (data) {
                        if(data['code']==200){
                            window.location.reload()
                        }else{
                            zlalert.alertError(data['message'])
                        }
                    }
                })
            }
        })
    })
});
